package com.tqjc.system.common.enums;

import com.tqjc.system.common.constant.AddTaskConstant;
import com.tqjc.system.common.entity.BO.AddTaskCacheInfoBO;
import com.tqjc.system.common.entity.BO.MaterialSpanBO;
import com.tqjc.system.common.enums.methods.AddTaskCacheInfoService;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @description:  缓存信息枚举
 * @Author: 86195
 * @Date: 2024/1/31 15:13
 **/
@NoArgsConstructor
@AllArgsConstructor
@Getter
public enum CacheInfoEnum implements AddTaskCacheInfoService {

    CAR_INDEX_MAP("1","int类型","天车目标位置集合"){
        @Override
        public List<AddTaskCacheInfoBO> getAddTaskCacheInfoList() {

            List<AddTaskCacheInfoBO> res = new ArrayList<>();
            for (Map.Entry<String, Integer> entry : AddTaskConstant.CAR_TARGET_INDEX_MAP.entrySet()) {
                //key  value
                AddTaskCacheInfoBO addTaskCacheInfoBO = AddTaskCacheInfoBO.builder().cacheDesc(this.getDesc())
                        .cacheDataType(this.getDataType()).cacheValue(entry.getValue()).cacheKey(entry.getKey())
                        .cacheId(this.getCacheId()).build();
                if("1_1".equals(entry.getKey())){
                    //废钢跨1号车
                    addTaskCacheInfoBO.setCacheName("废钢跨1号车");
                }
                if("1_2".equals(entry.getKey())){
                    //废钢跨2号车
                    addTaskCacheInfoBO.setCacheName("废钢跨2号车");
                }
                if("2_1".equals(entry.getKey())){
                    //渣钢跨1号车
                    addTaskCacheInfoBO.setCacheName("渣钢跨1号车");
                }
                if("2_2".equals(entry.getKey())){
                    //渣钢跨2号车
                    addTaskCacheInfoBO.setCacheName("渣钢跨2号车");
                }
                res.add(addTaskCacheInfoBO);
            }
            return res;
        }

        @Override
        public void updateInfo(String key, String value) {

            AddTaskConstant.CAR_TARGET_INDEX_MAP.put(key, Integer.valueOf(value));
        }
    },
    SPAN_STATUS_MAP("2","String类型","跨区状态集合。0：空闲状态，1：工作状态"){
        @Override
        public List<AddTaskCacheInfoBO> getAddTaskCacheInfoList() {
            List<AddTaskCacheInfoBO> res = new ArrayList<>();

            for (Map.Entry<String, MaterialSpanBO> entry : AddTaskConstant.SPAN_MAP.entrySet()) {
                MaterialSpanBO materialSpanBO = entry.getValue();
                AddTaskCacheInfoBO addTaskCacheInfoBO = AddTaskCacheInfoBO.builder().cacheDesc(this.getDesc())
                        .cacheDataType(this.getDataType()).cacheValue(materialSpanBO.getStatus()).cacheKey(entry.getKey())
                        .cacheId(this.getCacheId()).cacheName(materialSpanBO.getSpanName()).build();
                res.add(addTaskCacheInfoBO);
            }
            return res;
        }

        @Override
        public void updateInfo(String key, String value) {
            MaterialSpanBO materialSpanBO = AddTaskConstant.SPAN_MAP.get(key);
            materialSpanBO.setStatus(value);
            AddTaskConstant.SPAN_MAP.put(key,materialSpanBO);
        }
    },
    TANK_CAR_SCAN_FINISH_MAP("3","布尔类型","槽车扫描完成标识集合。true：扫描完成,false：扫描未完成"){
        @Override
        public List<AddTaskCacheInfoBO> getAddTaskCacheInfoList() {

            List<AddTaskCacheInfoBO> res = new ArrayList<>();
            AddTaskCacheInfoBO addTaskCacheInfoBO1 = AddTaskCacheInfoBO.builder().cacheDesc(this.getDesc())
                    .cacheDataType(this.getDataType()).cacheValue(AddTaskConstant.TANK_CAR_NO1_FINISH_FLAG).cacheKey("1")
                    .cacheId(this.getCacheId()).cacheName("1号槽车").build();
            AddTaskCacheInfoBO addTaskCacheInfoBO2 = AddTaskCacheInfoBO.builder().cacheDesc(this.getDesc())
                    .cacheDataType(this.getDataType()).cacheValue(AddTaskConstant.TANK_CAR_NO2_FINISH_FLAG).cacheKey("2")
                    .cacheId(this.getCacheId()).cacheName("2号槽车").build();
            AddTaskCacheInfoBO addTaskCacheInfoBO3 = AddTaskCacheInfoBO.builder().cacheDesc(this.getDesc())
                    .cacheDataType(this.getDataType()).cacheValue(AddTaskConstant.TANK_CAR_NO3_FINISH_FLAG).cacheKey("3")
                    .cacheId(this.getCacheId()).cacheName("3号槽车").build();
            res.add(addTaskCacheInfoBO1);
            res.add(addTaskCacheInfoBO2);
            res.add(addTaskCacheInfoBO3);
            return res;
        }

        @Override
        public void updateInfo(String key, String value) {
            if("1".equals(key)){
                AddTaskConstant.TANK_CAR_NO1_FINISH_FLAG = Boolean.valueOf(value);
            }
            if("2".equals(key)){
                AddTaskConstant.TANK_CAR_NO2_FINISH_FLAG =  Boolean.valueOf(value);
            }
            if("3".equals(key)){
                AddTaskConstant.TANK_CAR_NO3_FINISH_FLAG =  Boolean.valueOf(value);
            }

        }
    };



    private String cacheId;


    private String dataType;


    private String desc;


    public static CacheInfoEnum getCacheInfoEnumById(String cacheId){
        for (CacheInfoEnum value : CacheInfoEnum.values()) {
            if(value.cacheId.equals(cacheId)){
                return value;
            }
        }

        return null;

    }


}
